package com.harvey.study.data.structure.datastructure.stack;

import com.harvey.study.data.structure.datastructure.linkedlist.Node;

/**
 * 
 * date: 2021-04-26
 * desc: 栈链
 */
public class LinkStack<T> {
    private Node<T> top;
    private int length;

    public void push(T data){
        top = new Node<T>(data,top);
        length++;
    }

    public T pop(){
        Node<T> p = top;
        top = p.getNext();
        length--;
        return p.getData();
    }

    public T getHead(){
        if(isEmpty()){
            return null;
        }
        return top.getData();
    }

    public int size(){
        return length;
    }

    public boolean isEmpty(){
        return false;
    }

    public void clear(){
        top = null;
        length = 0;
    }

    public static void main(String[] args) {
        
    }
    
}
